package com.example.madman.yuejian.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.madman.yuejian.Bean.ShowpicBean;
import com.example.madman.yuejian.IP.IP_Config;
import com.example.madman.yuejian.R;

import java.util.List;


public class ShowPicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private  List<ShowpicBean> list;
    private Context context;
    private LayoutInflater inflater;
    private IP_Config IPAddress = new IP_Config();

    public ShowPicAdapter(Context context) {
        this.context=context;
        this.inflater = LayoutInflater.from(context);

    }
    public void setList(List<ShowpicBean> l){
        list=l;
        notifyDataSetChanged();

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.fragment_showpic,parent,false);
        RecyclerView.ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder( RecyclerView.ViewHolder holder, int position) {
        ShowpicBean bean = list.get(position);
        if(bean==null) return;
        final ViewHolder viewHolder= (ViewHolder) holder;
        viewHolder.title1.setText(bean.getShowpictitle());
       // viewHolder.title2.setText(bean.getShowpictitle());
        viewHolder.date1.setText(bean.getShowpicdate());
        //viewHolder.date2.setText(bean.getShowpicdate());
        Glide.with(context)
                .load(IPAddress.IP+"/yuejian/public/static/assets/img/"+bean.getShowpic())
                .placeholder(R.drawable.club)
                .into(viewHolder.pic1);
       /*Glide.with(context)
                .load(IPAddress.IP+"/yuejian/public/static/assets/img/"+bean.getShowpic())
                .placeholder(R.drawable.club)
                .into(viewHolder.pic2);*/


    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView title1,title2,date1,date2;
        ImageView pic1,pic2;

        public ViewHolder(View itemview) {
            super(itemview);
            title1 = (TextView)itemview.findViewById(R.id.showpic_text1);
            //title2 = (TextView)itemview.findViewById(R.id.showpic_text2);
            date1 = (TextView)itemview.findViewById(R.id.showpic_date1);
           // date2 = (TextView)itemview.findViewById(R.id.showpic_date2);
            pic1 = (ImageView)itemview.findViewById(R.id.showpic_image1);
          //  pic2 = (ImageView)itemview.findViewById(R.id.showpic_image2);
        }


    }
}
